<?php
class BoxSearchFoodPlace extends TRepeaterItemRenderer
{
	public function onDataBinding($param)
	{
		parent::onDataBinding($param);		
		if (count($this->Data)>0)
		{		
			$file = $this->Data->MainPhoto;
			$info = pathinfo($file);
			$file_name =  basename($file,'.'.$info['extension']); 
			$currentYear = date('Y', $this->Data->CreateDate);
			$currentMonth = date('m', $this->Data->CreateDate);
			$this->imgFoodPlacePhotoThumb->ImageUrl = $this->Request->UrlManagerModule->UrlPrefix."/useruploads/photos/food-place/".$currentYear."/".$currentMonth."/".$file_name.$this->Application->Parameters['FP_LIST_PHOTO_AFFFIX'].".".$info['extension'];	
			
			$this->lblFoodPlaceName->Text = $this->Data->Name;
			
			if ($this->Data->NearestMRT > 0) {
					$mrt = MRTRecord::finder()->findByPk($this->Data->NearestMRT);				
					$this->lblMRT->Text = $mrt->Name . " MRT";
			}
			
			// cuisine
			$foodPlaceCuisine = "";
			$criteria = new TActiveRecordCriteria;
			$criteria->Condition = "food_place_id = " . $this->Data->ID;
			$items = FoodPlaceCuisineRecord::finder()->findAll($criteria);				
			
			foreach ($items as $foodPlaceCuisineRecord) 
			{
				$cuisine = CuisineRecord::finder()->findByPk($foodPlaceCuisineRecord->CuisineID);
				$foodPlaceCuisine .= $cuisine->Cuisine . ", ";																														
			} 
			
			$foodPlaceCuisine = substr($foodPlaceCuisine,0,strlen($foodPlaceCuisine)-2);
			$this->lblCuisine->Text = $foodPlaceCuisine;
			
			// open until
			$this->lblOpenUntil->Text = "Open until 2AM";			
			if ($this->Data->OpenUntil > 0) {
					$closeTimeRecord = CloseTimeRecord::finder()->findByPk($this->Data->OpenUntil);				
					$this->lblOpenUntil->Text = "Open until " . $closeTimeRecord->CloseTime;
			} 
		}		
	}
}

?>